<!--
 * @FilePath     : /jquery/demo/101-14.html
 * @Description  : 添加一个"focused"的类名给那些有focus方法的元素
 * @Date         : 2025-03-27 09:14:13
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-03-27 09:17:21
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
    <style>
      .focused {
        background: #abcdef;
      }
    </style>
  </head>
  <body>
    <h2>添加一个"focused"的类名给那些有focus方法的元素</h2>
    <div id="content">
      <input tabindex="1" />
      <input tabindex="2" />
      <select tabindex="3">
        <option>select menu</option>
      </select>
      <div tabindex="4">a div</div>
    </div>

    <script src="/library/jquery.min.js"></script>
    <script src="/common/common.js"></script>
    <script>
      $('#content').delegate('*', 'focus blur', function (event) {
        var elem = $(this)
        setTimeout(function () {
          elem.toggleClass('focused', elem.is(':focus'))
        }, 0)
      })
      /*
      当上面元素聚焦时，或失去焦点时，
      元素会切换 '.focused' class 类名的有无，
      对应 聚焦时 添加或去除背景色；
      */
    </script>
  </body>
</html>
